<?php
/**
 * Created by PhpStorm.
 * User: jurentech
 * Date: 2019-09-29
 * Time: 23:34
 */

namespace app\master\controller;

class Order extends Base
{
//order_status	-	选填	订单状态，可以多个状态一起查询 结构如下（1,2,3,4） 0待支付 1已支付待发货 2已发货待签收 3已签收待评价（待评价也算作已完成订单） 4完成 5申请退货维权 6退货同意待用户发货 7用户发货待平台签收 8退换货订单完成'
//shipping_status	-	选填	收货状态，可以多个状态一起查询 结构如下（0,1,2）0未发货1已发货2已签收
//pay_status	-	选填	收货状态，可以多个状态一起查询 结构如下（0,1）0未支付1已支付
    /**
     * @return mixed订单列表
     */
    public function index()
    {
        return $this->fetch();
    }

    public function getOrderList()
    {
        $page['page'] = input("page");
        $page['limit'] = input("limit");
        $result['data'] = db('order')
            ->where(['isdelete' => 0])
            ->page($page['page'], $page['limit'])
            ->select();
        foreach ($result['data'] as $k=>$v){
            $result['data'][$k]['add_time']=date('Y-m-d H:i:s', $result['data'][$k]['add_time']);
            $result['data'][$k]['goods_name']=db('order_goods')->where(['order_id'=>$result['data'][$k]['order_id']])->value('goods_name');
            $result['data'][$k]['goods_num']=db('order_goods')->where(['order_id'=>$result['data'][$k]['order_id']])->value('goods_num');
            $result['data'][$k]['goods_price']=db('order_goods')->where(['order_id'=>$result['data'][$k]['order_id']])->value('goods_price');
            $result['data'][$k]['province']=db('region')->where(['id'=>$result['data'][$k]['province']])->value('name');
            $result['data'][$k]['city']=db('region')->where(['id'=>$result['data'][$k]['city']])->value('name');
            $result['data'][$k]['district']=db('region')->where(['id'=>$result['data'][$k]['district']])->value('name');
            $result['data'][$k]['twon']=db('region')->where(['id'=>$result['data'][$k]['twon']])->value('name');
        }
        $result['count'] = db('order')->where(['isdelete' => 0])->count();
        return $this->_table_return(0, "", $result['count'], $result['data']);
    }

    /**
     * @return mixed退款维权
     */
    public function refound(){
        return $this->fetch();
    }


    public function getRefoundOrderList()
    {
        $page['page'] = input("page");
        $page['limit'] = input("limit");
        $result['data'] = array();
        $result['count'] = 0;
        return $this->_table_return(0, "", $result['count'], $result['data']);
    }

    public function evaluate(){
        return $this->fetch();
    }

    public function getevaluateOrderList()
    {
        $page['page'] = input("page");
        $page['limit'] = input("limit");
        $result['data'] = array();
        $result['count'] = 0;
        return $this->_table_return(0, "", $result['count'], $result['data']);
    }
}